import React from 'react';
import { inject, observer } from 'mobx-react';
import { Spin } from 'antd'
import { WeaRightMenu, WeaTable } from 'ecCom';
import AccessItemOperation from "./AccessItemOperation";

/**
 * 考核设置-考核指标项
 * jiansong 2019/6/18
 */
@inject("accessItemListStore")
@observer
export default class AccessItemList extends React.Component {

    constructor(props) {
        super(props);
        this.store = this.props.accessItemListStore;
    }

    componentWillMount() {
        this.store.getTableDatas();
    }

    render() {
        const { menu } = this.props;
        const { data, canedit, loading, initEditForm, itemtype, isvalid } = this.store;
        const columns = [
            {
                title: '指标名称', dataIndex: 'itemname', width: '20%',
                render: (text, data) => {
                    return canedit ? <a href="javascript:void(0);" onClick={() => initEditForm(data)}>{text}</a> : text
                },
            },
            { title: '描述', dataIndex: 'itemdesc', width: '25%', },
            {
                title: '指标类型', dataIndex: 'itemtype', width: '10%',
                render: text => <span>{itemtype[text]}</span>
            },
            { title: '单位', dataIndex: 'itemunit', width: '10%', },
            {
                title: '计算公式', dataIndex: 'formula', width: '25%',
                render: (text, record) => <span>{this.getFormula(text, record)}</span>
            },
            {
                title: '是否启用', dataIndex: 'isvalid', width: '10%',
                render: text => <span>{isvalid[text]}</span>
            }
        ];
        return (
            <Spin spinning={loading}>
                <div style={{ height: '100vh' }}>
                    <WeaRightMenu datas={menu} showUrlItem={false}>
                        <WeaTable
                            columns={columns}
                            dataSource={data}
                            scroll={{ y:window.innerHeight-200 }}
                            pagination={{ total: data.length }}
                        />
                        <AccessItemOperation />
                    </WeaRightMenu>
                </div>
            </Spin>
        )
    }

    //获取计算公式
    getFormula(value, data) {
        if ("1" == value) {
            return "公式1[完成值/目标值*5]";
        } else if ("2" == value) {
            return "公式2[项目收款]";
        } else if ("3" == value) {
            return "公式3[项目验收]";
        } else if ("4" == value) {
            return "公式4[技术任务量]";
        } else if ("5" == value) {
            return "公式5[目标值/完成值*3.5]";
        } else if ("11" == value) {
            return "完成值/目标值*最大分制";
        } else if ("12" == value) {
            return data.formuladetail.replace("gval", "目标值").replace("cval", "完成值");
        } else if ("13" == value) {
            return "调用Java类：" + data.formuladetail;
        }
    }
}
;